#
# Copyright (C) 2017 The LineageOS Project
#
# SPDX-License-Identifier: Apache-2.0
#

TARGET_SPECIFIC_HEADER_PATH := $(PLATFORM_PATH)/include

# Bootloader
TARGET_BOOTLOADER_BOARD_NAME := $(PRODUCT_PLATFORM)
TARGET_NO_BOOTLOADER := true

# Platform
TARGET_BOARD_PLATFORM := $(PRODUCT_PLATFORM)

# Architecture
TARGET_ARCH := arm64
TARGET_ARCH_VARIANT := armv8-a
TARGET_CPU_ABI := arm64-v8a
TARGET_CPU_ABI2 :=
TARGET_CPU_VARIANT := cortex-a73
TARGET_CPU_VARIANT_RUNTIME := cortex-a73
TARGET_CPU_SMP := true

TARGET_2ND_ARCH := arm
TARGET_2ND_ARCH_VARIANT := armv8-a
TARGET_2ND_CPU_ABI := armeabi-v7a
TARGET_2ND_CPU_ABI2 := armeabi
TARGET_2ND_CPU_VARIANT := cortex-a73
TARGET_2ND_CPU_VARIANT_RUNTIME := cortex-a73

# Audio
AUDIO_FEATURE_ENABLED_EXTENDED_COMPRESS_FORMAT := true
BOARD_USES_ALSA_AUDIO := true
USE_CUSTOM_AUDIO_POLICY := 1
BOARD_SUPPORTS_SOUND_TRIGGER := true
BOARD_SUPPORTS_OPENSOURCE_STHAL := true
#AUDIO_FEATURE_ENABLED_AHAL_EXT := true

# Bluetooth
TARGET_USE_QTI_BT_STACK := true
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := $(PLATFORM_PATH)/bluetooth

# Build System
BUILD_BROKEN_DUP_RULES := true
BUILD_BROKEN_DUP_SYSPROP := true
BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES := true
BUILD_BROKEN_ENFORCE_SYSPROP_OWNER := true
RELAX_USES_LIBRARY_CHECK := true
BUILD_BROKEN_VENDOR_PROPERTY_NAMESPACE := true

# Boot Animtion
TARGET_BOOTANIMATION_HALF_RES := true

# Camera
TARGET_USES_QTI_CAMERA_DEVICE := true
USE_CAMERA_STUB := false

# Charger
WITH_LINEAGE_CHARGER := false

# CNE and DPM
BOARD_USES_QCNE := true

# Crypto
TARGET_HW_DISK_ENCRYPTION := true

# Display
MAX_EGL_CACHE_KEY_SIZE := 12*1024
MAX_EGL_CACHE_SIZE := 2048*1024
TARGET_USES_GRALLOC1 := true
ifeq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.14 4.19))
TARGET_USES_GRALLOC4 := true
endif
TARGET_USES_HWC2 := true
TARGET_USES_ION := true
OVERRIDE_RS_DRIVER := libRSDriver_adreno.so

#TARGET_USES_DRM_PP := true

# DRM
TARGET_ENABLE_MEDIADRM_64 := true

# Extended Filesystem Support
TARGET_EXFAT_DRIVER := exfat

# FM
ifeq ($(BOARD_HAVE_QCOM_FM),true)
AUDIO_FEATURE_ENABLED_FM_POWER_OPT := true
BOARD_HAS_QCA_FM_SOC := cherokee
endif

# GPS
BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := default
GNSS_HIDL_VERSION := 2.1
LOC_HIDL_VERSION := 4.0

# HIDL
DEVICE_MANIFEST_FILE := $(PLATFORM_PATH)/configs/vintf/manifest.xml
DEVICE_MATRIX_FILE := $(PLATFORM_PATH)/configs/vintf/compatibility_matrix.xml
DEVICE_FRAMEWORK_MANIFEST_FILE := $(PLATFORM_PATH)/configs/vintf/framework_manifest.xml

# Init
TARGET_INIT_VENDOR_LIB := //$(PLATFORM_PATH):libinit_sdm660
TARGET_RECOVERY_DEVICE_MODULES := libinit_sdm660

# Kernel
BOARD_KERNEL_CMDLINE := \
    console=ttyMSM0,115200n8 androidboot.console=ttyMSM0 earlycon=msm_serial_dm,0xc170000 \
    g_android.luns=1 g_android.removable=1 g_android.cdrom=1 androidboot.hardware=qcom \
    user_debug=31 msm_rtb.filter=0x37 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 sched_enable_hmp=1 sched_enable_power_aware=1 \
    service_locator.enable=1 swiotlb=1 androidboot.configfs=true \
    androidboot.usbcontroller=a800000.dwc3 \
    androidboot.selinux=permissive
BOARD_KERNEL_BASE := 0x00000000
BOARD_KERNEL_PAGESIZE := 4096
BOARD_KERNEL_IMAGE_NAME := Image.gz-dtb
TARGET_KERNEL_ARCH := arm64
TARGET_KERNEL_HEADER_ARCH := arm64
TARGET_KERNEL_CLANG_COMPILE := true
TARGET_KERNEL_ADDITIONAL_FLAGS := \
    HOSTCFLAGS="-fuse-ld=lld -Wno-unused-command-line-argument"
#TARGET_KERNEL_VERSION := 4.4

# Lights
TARGET_PROVIDES_LIBLIGHT := true

# Metadata
#BOARD_USES_METADATA_PARTITION := true

# Media
BOARD_SECCOMP_POLICY := $(PLATFORM_PATH)/seccomp
TARGET_ENABLE_MEDIADRM_64 := true

# Partitions
BOARD_FLASH_BLOCK_SIZE := 131072
BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 67108864
BOARD_CACHEIMAGE_PARTITION_SIZE := 268435456
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
TARGET_USERIMAGES_USE_EXT4 := true
TARGET_USERIMAGES_USE_F2FS := true
TARGET_USES_MKE2FS := true
#BOARD_BUILD_SYSTEM_ROOT_IMAGE := true

# Peripheral manager
TARGET_PER_MGR_ENABLED := true

# Power
TARGET_USES_INTERACTION_BOOST := true

# Properties
TARGET_ODM_PROP += $(PLATFORM_PATH)/properties/odm.prop
TARGET_PRODUCT_PROP += $(PLATFORM_PATH)/properties/product.prop
TARGET_SYSTEM_PROP += $(PLATFORM_PATH)/properties/system.prop
TARGET_SYSTEM_EXT_PROP += $(PLATFORM_PATH)/properties/system_ext.prop
TARGET_VENDOR_PROP += $(PLATFORM_PATH)/properties/vendor.prop

TARGET_FS_CONFIG_GEN += \
    $(PLATFORM_PATH)/config.fs \

# QCOM hardware
ifeq ($(ADRENO_GLES_BUILD_CONFIG),10)
BOARD_USES_QCOM_HARDWARE := true
ifeq ($(TARGET_KERNEL_VERSION),4.4)
OVERRIDE_QCOM_HARDWARE_VARIANT := sdm660-legacy-um
else
OVERRIDE_QCOM_HARDWARE_VARIANT := $(PRODUCT_PLATFORM)
endif
endif

# Recovery
#BOARD_USES_RECOVERY_AS_BOOT := true
TARGET_NO_RECOVERY := false
#BOARD_USES_FULL_RECOVERY_IMAGE := true
TARGET_RECOVERY_DEVICE_DIRS += $(PLATFORM_PATH)
TARGET_RECOVERY_FSTAB := $(PLATFORM_PATH)/rootdir/root/recovery.fstab
TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"

# RIL
ENABLE_VENDOR_RIL_SERVICE := true
CUSTOM_APNS_FILE := $(PLATFORM_PATH)/configs/cmcc_apns.xml

# Root
BOARD_ROOT_EXTRA_SYMLINKS := \
    /vendor/dsp:/dsp \
    /vendor/firmware_mnt:/firmware \
    /vendor/bt_firmware:/bt_firmware \
    /mnt/vendor/persist:/persist

# SELinux
SELINUX_IGNORE_NEVERALLOWS := true
include device/qcom/sepolicy-legacy-um/SEPolicy.mk
BOARD_VENDOR_SEPOLICY_DIRS += $(PLATFORM_PATH)/sepolicy/vendor
SYSTEM_EXT_PUBLIC_SEPOLICY_DIR += $(PLATFORM_PATH)/sepolicy/public
SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += $(PLATFORM_PATH)/sepolicy/private

# Vendor Security Patch Level
VENDOR_SECURITY_PATCH := 2021-12-01

#Treble
PRODUCT_FULL_TREBLE_OVERRIDE := false
BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED := true

# VNDK
BOARD_VNDK_VERSION := current
#TARGET_COPY_OUT_PRODUCT := system/product
TARGET_COPY_OUT_VENDOR := system/vendor

# Wifi
BOARD_HAS_QCOM_WLAN                 := true
BOARD_WLAN_DEVICE                   := qcwcn
WPA_SUPPLICANT_VERSION              := VER_0_8_X
BOARD_WPA_SUPPLICANT_DRIVER         := NL80211
BOARD_WPA_SUPPLICANT_PRIVATE_LIB    := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
BOARD_HOSTAPD_DRIVER                := NL80211
BOARD_HOSTAPD_PRIVATE_LIB           := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
WIFI_DRIVER_FW_PATH_STA             := "sta"
WIFI_DRIVER_FW_PATH_AP              := "ap"
WIFI_DRIVER_FW_PATH_P2P             := "p2p"
WIFI_HIDL_FEATURE_DUAL_INTERFACE    := true
WIFI_HIDL_FEATURE_AWARE             := true
WIFI_HIDL_UNIFIED_SUPPLICANT_SERVICE_RC_ENTRY    := true
